package com.ldp.designpatterns.study.observer;

import com.ldp.designpatterns.study.observer.observer.ConcreteObserver;
import com.ldp.designpatterns.study.observer.observer.Observer;
import com.ldp.designpatterns.study.observer.subject.ConcreteSubject;

/**
 * @ClassName ObserverTest
 * @Description TODO 观察者模式 一个对象（目标对象）的状态发生改变，所有的依赖对象（观察者对象）都将得到通知，进行广播通知。
 * @Author lindipei
 * @Date 2023/10/18 13:53
 */
public class ObserverTest {
    public static void main(String[] args) {
        ConcreteSubject subject = new ConcreteSubject();

        Observer observer1 = new ConcreteObserver("观察者1");
        Observer observer2 = new ConcreteObserver("观察者2");

        subject.addObserver(observer1);
        subject.addObserver(observer2);

        subject.setState(10);
        subject.setState(20);

        subject.removeObserver(observer1);

        subject.setState(30);
    }
}
